<?php

if ( !defined('AREA') ) { die('Access denied'); }

session_start();

// Require configuration
require(DIR_ROOT . '/config.php');
// 設定include路徑
set_include_path('.' . __PS__ . './lib/'
						. __PS__ . DIR_ROOT . '/lib/'
						. __PS__ . get_include_path() );
// 載入ADODB資料庫函式庫
require_once( 'adodb5/adodb.inc.php' );
require_once( DIR_CORE . 'fn.common.php' );
require_once( DIR_CORE . 'fn.fs.php' );
require_once( DIR_CORE . 'fn.images.php' );
require_once( DIR_CORE . 'fn.init.php' );
require_once( DIR_CORE . 'class.registry.php' );

//載入PHPMAILER
include_once( 'phpMailer/class.phpmailer.php' );

// Set configuration options from config.php to registry
Registry::set('config', $config);
unset($config);

// Connect to database

define('ADODB_FETCH_ASSOC',2);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

$_db =  &NewADOConnection(Registry::get('config.db_type'));
$_db->Connect(
    Registry::get('config.db_host'),
    Registry::get('config.db_user'),
    Registry::get('config.db_password'),
    Registry::get('config.db_name')
);
$_db->Execute("SET NAMES 'utf8';");

if (!$_db) {
	fn_error(debug_backtrace(), '無法聯結資料庫', false);
}
// 載入Function
require_once( 'function.php');
// initialize templater
fn_init_templater('front');
date_default_timezone_set('Asia/Taipei');


include_once "facebook.php";
$facebook = new Facebook(array(
		'appId'  => $fbconfig['appid'],
		'secret' => $fbconfig['secret'],
		'cookie' => true,
));
$user = $facebook->getUser();
if(!empty($user))
{
	try {
  	$facebook_uid    =   $facebook->getUser();
  	$fbme     =   $facebook->api('/me');
		$uid = fn_checkUserAccExist($facebook_uid);
		if( $uid ){
			fn_saveLoginAuthSession('F', $uid);	
		}
  } catch (FacebookApiException $e) { 
  	echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
  }
}

Registry::get('tpl')->register_function('fn_get_notification', 'fn_get_notification');
?>